#ifdef RW_PROCS                               /* begin code for "2nd" include */

#ifdef INCLUDE_PNEU_TEST

      case  MAKEINT('D','T'):
        parm_len = DoTPDT(p_cmd,p_resp_parm);
        break;

      case  MAKEINT('E','T'):
        parm_len = DoTPET(p_cmd,p_resp_parm);
        break;

      case  MAKEINT('R','T'):
        parm_len = DoTPRT(p_cmd,p_resp_parm);
        break;

#endif

      case  MAKEINT('I','O'):
        parm_len = DoTPIO(p_cmd,p_resp_parm);
        break;

#if 0
      case  MAKEINT('C','F'):
        parm_len = DoTPCF(p_cmd,p_resp_parm);
        break;

      case  MAKEINT('C','P'):
        parm_len = DoTPCP(p_cmd,p_resp_parm);
        break;

      case  MAKEINT('C','T'):
        parm_len = DoTPCT(p_cmd,p_resp_parm);
        break;

      case  MAKEINT('P','V'):
	parm_len = DoTPPV(p_cmd,p_resp_parm);
	break;

      case  MAKEINT('V','P'):
	parm_len = DoTPVP(p_cmd,p_resp_parm);
	break;

      case  MAKEINT('V','T'):
	parm_len = DoTPVT(p_cmd,p_resp_parm);
	break;

      case  MAKEINT('P','F'):
	parm_len = DoTPPF(p_cmd,p_resp_parm);
	break;

      case  MAKEINT('F','P'):
	parm_len = DoTPFP(p_cmd,p_resp_parm);
	break;
#endif

      case MAKEINT( 'M','D' ):
        parm_len = DoTPMD(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'Z','P' ):                    /*  do a 4 pt calib on a pres. sensor and save results in eeprom */
        parm_len = DoTPZP(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'Z','F' ):                    /* do a 4 pt calib on a flow sensor and save results in eeprom   */
        parm_len = DoTPZF(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'Z','T' ):                    /* do 2 pt linear calib for the temp sensor; store results in EEPROM */
        parm_len = DoTPZT(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'Z','S' ):                    /* do 2 pt linear calib for septum prg reg; store results in EEPROM */
        parm_len = DoTPZS(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'Q','S' ):
        parm_len = DoTPQS(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'Z','D' ):                    /* prgrm default mask (of specified type) to the specified module   */
        parm_len = DoTPZD(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'R','P' ):
        parm_len = DoTPRP(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'S','P' ):
        parm_len = DoTPSP(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'R','F' ):
        parm_len = DoTPRF(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'S','F' ):
        parm_len = DoTPSF(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'C','J' ):
        parm_len = DoTPCJ(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'J','S' ):
        parm_len = DoTPJS(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'Y','Q' ):
        parm_len = DoTPYQ(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'Y','P' ):
        parm_len = DoTPYP(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'Y','T' ):
        parm_len = DoTPYT(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'p','k' ):
        parm_len = DoTPpk(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'p','o' ):
        parm_len = DoTPpo(p_cmd, p_resp_parm );
        break;

      case MAKEINT( 'I','F' ):
        parm_len = DoTPIF(p_cmd, p_resp_parm, pFRONT_INLET );
        break;

      case MAKEINT( 'I','B' ):
        parm_len = DoTPIF(p_cmd, p_resp_parm, pBACK_INLET );
        break;

#endif                                        /* end   code for "2nd" include */


#ifndef RW_PROCS                              /* begin code for "1st" include */


#define MIN(A,B) ( ((A) < (B)) ? (A) : (B) )

#ifdef INCLUDE_PNEU_TEST

BIT8 ParseTestEntry ( BIT8 *entry, U_INT16 index );
void TestIt( void );
void RestartTestScript( void );

#endif

U_INT16 AddAdcOffset( U_INT16 volts );
U_INT16 SubtractAdcOffset( U_INT16 volts );


extern BIT8 InitInletEEPROM(U_INT8 module, U_INT16 type, U_INT16 range, U_INT16 scale, U_INT16 snh, U_INT16 snl, U_INT16 bd);
extern BIT8 InitDetEEPROM ( U_INT8 module, U_INT16 type, U_INT16 range, U_INT16 scale, U_INT16 snh, U_INT16 snl, U_INT16 bd);
extern BIT8 InitAuxEEPROM ( U_INT8 module, U_INT16 type, U_INT16 range, U_INT16 scale, U_INT16 snh, U_INT16 snl, U_INT16 bd);


BIT8 ParamPresent( CMD_TYPE *p_cmd, U_INT16 parm_num )
{

    return ( p_cmd->parmv[0] >= parm_num ) && ( StrLen( &p_cmd->parms[p_cmd->parmv[ parm_num ]] ) != 0 );

}



/***********************************************************************/
/* FUNCTION: GetALongWordParam                                         */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: number coversion, hex if preceeded by '0x',  dec otherwise */
/*                                                                     */
/* RETURNED VALUE: 32 bit unsigned int                                 */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS: value undefined if conversion fails.                   */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

UI_ERR GetALongWordParam( CMD_TYPE *p_cmd, U_INT16 num, U_INT32 *value )
{

    UI_ERR  error;
    U_INT32 temp;

    error = OK;

    if ( StrLen( &p_cmd->parms[p_cmd->parmv[num]] ) != 0 )
    {
         if (( StrLen ( &p_cmd->parms[p_cmd->parmv[num]] ) > 2 ) &&
            (( (&p_cmd->parms[p_cmd->parmv[num]])[0] == '0' ) &&
	    ( (&p_cmd->parms[p_cmd->parmv[num]])[1] == 'x' ) ) )
         {
              error=HexToInt( &(&p_cmd->parms[p_cmd->parmv[num]])[2], (U_INT32 *) &temp );
         }
         else 
         {
              error=DecToInt( &p_cmd->parms[p_cmd->parmv[num]], 0, (INT32 *) &temp );
         }
     
         if ( error == OK )
         {
              *value = temp;
         }
    }
    else
    {
         error = INVALID_PARAM;
    }

    return error;
}

UI_ERR GetReal( CMD_TYPE *p_cmd, U_INT16 parm_num, float *value )
{
    UI_ERR error;
    INT32  number;

    error = DecToInt( &p_cmd->parms[p_cmd->parmv[ parm_num ]],  3, &number );

    if ( error == OK ) *value = (float)number / 1000;

    return error;
}


UI_ERR GetDouble( CMD_TYPE *p_cmd, U_INT16 parm_num, float *value )
{
    UI_ERR error;
    INT32  number;

    error = DecToInt( &p_cmd->parms[p_cmd->parmv[ parm_num ]],  6, &number );

    if ( error == OK ) *value = (float)number / 1000000;

    return error;
}


#ifdef INCLUDE_PNEU_TEST

INT16 DoTPDT(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   U_INT16 index;
   UI_ERR  error;
 
   error = OK;
 
   if ( GetAWordParam( p_cmd, 1, &index ) != OK ) error = INVALID_PARAM;
   if ( ParamPresent( p_cmd, 2) == FALSE )        error = INVALID_PARAM;

   if (( error == OK ) && ( ParseTestEntry ( &p_cmd->parms[p_cmd->parmv[ 2 ]], index ) == TRUE ))
   {
        return  PutAsciiParam( (BIT8 *)"OK ", p_resp_parm );
   }
   else
   {
        return  PutAsciiParam( (BIT8 *)"?? ", p_resp_parm );
   }

}

INT16 DoTPET(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{

   TestIt();
   return 0;
}


INT16 DoTPRT(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{

   RestartTestScript();
   return 0;
}

#endif

INT16 DoTPMD(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   U_INT16 rank;
   U_INT16 i;
   UI_ERR  error;
   float   matrix[ 16 ];

   error = OK;

   i = 1;

   if ( GetAWordParam( p_cmd, 1, &rank ) != OK ) error = INVALID_PARAM;
   if ( rank > 4 )                               error = PARAM_TOO_LARGE;
   if ( p_cmd->parmv[0] != rank*rank+1 )         error = MISSING_PARAM;

   if ( error == OK )
   {
       for ( i = 0 ; i < rank*rank ; i++ )
       {
           if ( ( error = GetReal( p_cmd, i+2, &matrix[ rank*(i/rank) + (i%rank) ] ) ) != OK ) break;
       }
   }

   if ( error == OK )
   {
        return  PutHexParam  ( (INT32)Determinate( matrix, rank ), p_resp_parm );
   }
   else 
   {
        CmdErrorHandler( p_cmd, i, error );
        return  PutAsciiParam( (BIT8 *)"?? ", p_resp_parm ) + PutIntParam( i, p_resp_parm+3, 0 );
   }

}


#include <i_op.h>

INT16 DoTPIO(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{

   INTERRUPTS_OFF

   Inst_Status.Pneu.Block_Foreground_Interrupts = TRUE;

   INTERRUPTS_ON

   return 0;
}



INT16 DoTPpk(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   U_INT16 addr;
   U_INT32 data;
   UI_ERR  error;

   error = OK;
   data  = 0;

   if ( GetAWordParam( p_cmd, 1, &addr ) != OK ) error = INVALID_PARAM;

   if ( error == OK )
   {
       if ( !PcbPeek( addr, &data ))
       {
            error = NOT_ALLOWED;
       }
   }

   if ( error == OK )
   {
        return  PutHexParam  ( data, p_resp_parm );
   }
   else 
   {
        return  PutAsciiParam( (BIT8 *)"?? ", p_resp_parm );
   }

}


INT16 DoTPpo(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   U_INT16 addr;
   U_INT32 data;
   UI_ERR  error;

   error = OK;

   if ( GetAWordParam      ( p_cmd, 1, &addr ) != OK ) error = INVALID_PARAM;
   if ( GetALongWordParam  ( p_cmd, 2, &data ) != OK ) error = INVALID_PARAM;

   if ( error == OK )
   {
       if ( !PcbPoke( addr, data ) )
       {
            error = NOT_ALLOWED;
       }
   }

   if ( error == OK )
   {
        return  PutAsciiParam( (BIT8 *)"OK ", p_resp_parm );
   }
   else 
   {
        return  PutAsciiParam( (BIT8 *)"?? ", p_resp_parm );
   }

}



INT16 DoTPZD(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   UI_ERR  error;

   U_INT16 module       = 0;
   U_INT16 type         = 0;
   U_INT16 sn_high      = 0;
   U_INT16 sn_low       = 0;
   U_INT16 build_date   = 0;
   U_INT16 tester_id    = 0;
   
  
   error = OK;


/**begin_doc**/
    /*                                                                                                   */
    /*  program a default mask (of the specified type) to the specified module                           */
    /*                                                                                                   */
    /*  W A R N I N G !!  this command will obilterate any information stored in the specified eerpom.   */
    /*                    it must be used before any of the other Z commands.                            */
    /*                                                                                                   */
    /*                                                                                                   */
    /*   TPZD module_num, type, serial_no_high, serial_no_low, build_date, test_station_id               */
    /*                                                                                                   */
    /*   module_num   0 - frnt inlet        where is the manifold we are messing with?                   */
    /*                1 - back inlet                                                                     */
    /*                2 - frnr det                                                                       */
    /*                3 - back det                                                                       */
    /*                4 - pneu aux                                                                       */
    /*                                                                                                   */
    /*                                                                                                   */
    /*  type          the module type (in hex, preceeded by '0x' example:  0x0102 = EPC SS)              */
    /*                                                                                                   */
    /*                0100  EPC PP                                                                       */
    /*                0101  EPC COC                                                                      */
    /*                0102  EPC SS                                                                       */
    /*                010f  EPC JITB  Jack In The Box, special calibration manifold                      */
    /*                                                                                                   */
    /*                                                                                                   */
    /*                0201  Man FID                                                                      */
    /*                0202  Man TCD                                                                      */
    /*                0203  Man ECD                                                                      */
    /*                0204  Man NPD                                                                      */
    /*                0205  Man FPD                                                                      */
    /*                                                                                                   */
    /*                0211  EPC FID                                                                      */
    /*                0212  EPC TCD                                                                      */
    /*                0213  EPC ECD  / Nutronics / 2 Ch                                                  */
    /*                0214  EPC NPD                                                                      */
    /*                0215  EPC FPD                                                                      */
    /*                0216  ( reserved; sig. P.C.B. = AIB )                                              */
    /*                0217  EPC uECD / Nutronice / 1 Ch                                                  */
    /*                0218  EPC FPD  / uMachined / 1 Ch                                                  */
    /*                                                                                                   */
    /*                0300  Pres Aux                                                                     */
    /*                                                                                                   */
    /* serial_no_high  16bit hex value (preceeded by 0x), for the upper half of a 32 bit serial number   */
    /* serial_no_low   16bit hex value (preceeded by 0x), for the lower half of a 32 bit serial number   */
    /*                                                                                                   */
    /* build date      16 bit hex value ( preceeded by 0x), (DDDDDMMMMYYYYYYY) (d*2048)+(m*128)+(y-1980) */
    /*                 example   11-20-93 = 20*2048  + 11*128 + 1993-1980 = 42381 = 0xa58d               */
    /*                                                                                                   */
    /* test_station_id a 16bit value (preceeded by 0x if hex) representing an ID number for the tester   */
/**end_doc**/

   if (( p_cmd->parmv[0] != 5 ) && ( p_cmd->parmv[0] != 6 ))  error = MISSING_PARAM;

   if ( error == OK )  error = GetAWordParam( p_cmd,  1, &module      );
   if ( error == OK )  error = GetAWordParam( p_cmd,  2, &type        );
   if ( error == OK )  error = GetAWordParam( p_cmd,  3, &sn_high     );
   if ( error == OK )  error = GetAWordParam( p_cmd,  4, &sn_low      );
   if ( error == OK )  error = GetAWordParam( p_cmd,  5, &build_date  );

   tester_id = 0xffff;
   if (( error == OK ) && ( p_cmd->parmv[0] == 6 ))  error = GetAWordParam( p_cmd,  6, &tester_id  );

   if ( error == OK )
   {
       switch ( type )
       {
            case 0x0100:  /* pp  */
            case 0x0101:  /* coc */
            case 0x0102:  /* ss  */
            case 0x0103:  /* ptv */
            case 0x0104:  /* man pp  */
            case 0x0105:  /* man coc */
            case 0x0106:  /* man ss  */
            case 0x0107:  /* unknown */
            case 0x0108:  /* none */
            case 0x0109: /* "ad-hoc" AC sim dist inlet */
            case 0x010a:  /* g-ptv */
            case 0x010b:  /* man aci */
            case 0x010c: /* HP PTV (CIS4)   */
            case 0x010d: /* "supported" AC sim dist inlet ; also RGA & NGA */
            case 0x010e: /* CIS3 inlet      */
            case 0x010f: /* JILL */
            case 0x0110: /* VI */
                         if ( InitInletEEPROM( module, 
                                               type,
                                               0xa854, 
                                               0xa0, 
                                               sn_high, 
                                               sn_low, 
                                               build_date ) == TRUE ) error = OK;
                         else  error = INVALID_PARAM;
                         break;
    
            case 0x0201:
            case 0x0202:
            case 0x0203:
            case 0x0204:
            case 0x0205:
            case 0x0211:
            case 0x0212:
            case 0x0213:
            case 0x0214:
            case 0x0215:
            case 0x0217:
            case 0x0218: if ( InitDetEEPROM ( module, 
                                              type,
                                              0xa854, 
                                              0xa0, 
                                              sn_high, 
                                              sn_low, 
                                              build_date ) == TRUE )  error = OK;
                         else error = INVALID_PARAM;
                         break;
    
            case 0x0300: if ( InitAuxEEPROM ( module, 
                                              type,
                                              0xa854, 
                                              0xa0, 
                                              sn_high, 
                                              sn_low, 
                                              build_date ) == TRUE )  error = OK;
                         else error = INVALID_PARAM;
                         break;
    
          default: error = INVALID_PARAM;
       }

       InitTestStationId( module, tester_id );
   }


   if ( error == OK ) return  PutAsciiParam( (BIT8 *)"OK",     p_resp_parm  );
   else               return  PutAsciiParam( (BIT8 *)"??",     p_resp_parm );

}



INT16 DoTPYQ(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   UI_ERR  error;
   U_INT16 module     = 0;
   int     len        = 0;
   U_INT16 gas_type   = 0;
   U_INT16 gas_num    = 0;
   float   alpha      = 0.0;
   float   beta       = 0.0;
   float   max_flow   = 0.0;

/**begin_doc**/
    /*                                                                                                   */
    /*  Writes converted frit constants to EEPROM                                                        */
    /*                                                                                                   */
    /*   TPYQ module_num, gas_num, gas_type, alpha, beta, max_flow                                       */
    /*                                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
    /*   module_num   0 - frnt inlet        where is the manifold we are messing with?                   */
    /*                1 - back inlet                                                                     */
    /*                2 - frnr det                                                                       */
    /*                3 - back det                                                                       */
    /*                4 - pneu aux                                                                       */
    /*                                                                                                   */
    /*                                                                                                   */
    /*   gas_num      1 - fuel                                                                           */
    /*                2 - air / ref / anode purge                                                        */
    /*                3 - makeup                                                                         */
    /*                                                                                                   */
    /*                                                                                                   */
    /*   gas_type     0 - N2                                                                             */
    /*                1 - H2                                                                             */
    /*                2 - He                                                                             */
    /*                3 - ArMe                                                                           */
    /*                4 - O2                                                                             */
    /*                5 - Air                                                                            */
    /*                6 - Ar                                                                             */
    /*                                                                                                   */
    /*   alpha - frit constant  real, 3 decimal digits                                                   */
    /*   beta  - frit constant  real, 3 decimal digits                                                   */
    /*                                                                                                   */
    /*   max flow - max flow in sccm   real, 3 decimal digits                                            */
    /*                                                                                                   */
/**end_doc**/
   
   error = OK;

   if ( p_cmd->parmv[0] != 6 )  error = MISSING_PARAM;

   if ( error == OK )  error = GetAWordParam( p_cmd,  1, &module      );
   if ( error == OK )  error = GetAWordParam( p_cmd,  2, &gas_num     );
   if ( error == OK )  error = GetAWordParam( p_cmd,  3, &gas_type    );

   if ( error == OK )  error = GetReal( p_cmd,  4, &alpha    );
   if ( error == OK )  error = GetReal( p_cmd,  5, &beta     );
   if ( error == OK )  error = GetReal( p_cmd,  6, &max_flow );

   if  ( module   > 4 )                      error = INVALID_PARAM;
   if  ( gas_type > 6 )                      error = INVALID_PARAM;
   if (( gas_num  < 1 ) || ( gas_num  > 3 )) error = INVALID_PARAM;

   if ( error == OK )   error = WriteFritConstants( module, gas_num, (GAS_TYPE)gas_type, alpha, beta, max_flow );

   len = 0;

   if ( error == OK ) len += PutAsciiParam( (BIT8 *)"OK",     p_resp_parm );
   else               len += PutAsciiParam( (BIT8 *)"??",     p_resp_parm );

   return len;
}


INT16 DoTPYP(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   UI_ERR  error        = OK;
   U_INT16 module       = 0;
   int     len          = 0;
   U_INT16 dcm2_per_iu  = 1;
   U_INT16 gas_num      = 0;
   float   range        = 0.0;
   float   offset       = 0.0;
   float   span         = 0.0;
   float   doffset_dt   = 0.0;
   float   dspan_dt     = 0.0;

/**begin_doc**/
    /*                                                                                                   */
    /*  Writes converted pressure sensor constants to EEPROM                                             */
    /*                                                                                                   */
    /*   TPYP module_num, gas_num, range, offset, span, doffset_dt, dspan_dt                             */
    /*                                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
    /*   module_num   0 - frnt inlet        where is the manifold we are messing with?                   */
    /*                1 - back inlet                                                                     */
    /*                2 - frnr det                                                                       */
    /*                3 - back det                                                                       */
    /*                4 - pneu aux                                                                       */
    /*                                                                                                   */
    /*                                                                                                   */
    /*   gas_num      1 - fuel                                                                           */
    /*                2 - air / ref / anode purge                                                        */
    /*                3 - makeup                                                                         */
    /*                                                                                                   */
    /*                                                                                                   */
    /*   range        max psi value for pressure sensor                     real, 3 decimal digits       */
    /*   offset       offset voltage for p sensor at 25C (V)                real, 3 decimal digits       */
    /*   span         pres sensor voltage at max psi, 25C (V)               real, 3 decimal digits       */
    /*   doffset_dt   change (mV) in sensor offset with 1C change in temp   real, 6 decimal digits       */
    /*   dspan_dt     change (mV)in sensor span with 1C change in temp      real, 6 decimal digits       */
    /*                                                                                                   */
    /*                                                                                                   */
/**end_doc**/
   
   if ( p_cmd->parmv[0] != 7 )  error = MISSING_PARAM;

   if ( error == OK )  error = GetAWordParam( p_cmd,  1, &module      );
   if ( error == OK )  error = GetAWordParam( p_cmd,  2, &gas_num     );

   if ( error == OK )  error = GetReal( p_cmd,  3, &range      );
   if ( error == OK )  error = GetReal( p_cmd,  4, &offset     );
   if ( error == OK )  error = GetReal( p_cmd,  5, &span       );
   if ( error == OK )  error = GetReal( p_cmd,  6, &doffset_dt );
   if ( error == OK )  error = GetReal( p_cmd,  7, &dspan_dt   );

   if  ( module   > 4 )                      error = INVALID_PARAM;
   if (( gas_num  < 1 ) || ( gas_num  > 3 )) error = INVALID_PARAM;

   if      (( range < 110 ) && ( range > 25 )) dcm2_per_iu = 0x00a0;
   else if (( range <= 25 ) && ( range > 0  )) dcm2_per_iu = 0x0080;
   else                                        dcm2_per_iu = 0x0140;

   range = range * 68947.57 / dcm2_per_iu;
 
   doffset_dt /= 1000;  /* convert to volts */
   dspan_dt   /= 1000;  /* convert to volts */

   len = 0;

   if ( error == OK ) 
   {
        switch( SavePsParms( module, gas_num, (U_INT16)range, dcm2_per_iu, offset, span, doffset_dt, dspan_dt ))
        {
            case OK: len += PutAsciiParam( (BIT8 *)"OK,",          p_resp_parm + len    );
                    break;
            case  OVFLOW_PS_OFFSET:
                    len += PutAsciiParam( (BIT8 *)"OVERFLOW OFFSET,",         p_resp_parm + len    );
                    break;
            case  OVFLOW_PS_SPAN:
                    len += PutAsciiParam( (BIT8 *)"OVERFLOW SPAN,",           p_resp_parm + len    );
                    break;
            case  OVFLOW_PS_DOFFSET:
                    len += PutAsciiParam( (BIT8 *)"OVERFLOW dOFFSET/dT,",     p_resp_parm + len    );
                    break;
            case  OVFLOW_PS_DSPAN:
                    len += PutAsciiParam( (BIT8 *)"OVERFLOW dSPAN/dT,",       p_resp_parm + len    );
                    break;
            case  ZERO_PS_RANGE:
                    len += PutAsciiParam( (BIT8 *)"ZERO RANGE,",              p_resp_parm + len    );
                    break;
            case  ZERO_PS_DCM2:
                    len += PutAsciiParam( (BIT8 *)"ZERO SCALE,",              p_resp_parm + len    );
                    break;
            case  ZERO_PS_OFFSET:
                    len += PutAsciiParam( (BIT8 *)"ZERO OFFSET,",             p_resp_parm + len    );
                    break;
            case  ZERO_PS_SPAN:
                    len += PutAsciiParam( (BIT8 *)"ZERO SPAN,",               p_resp_parm + len    );
                    break;
           case EEPROM_WRITE_ERROR:
                   len += PutAsciiParam( (BIT8 *)"CANT WRITE TO EEPROM, ",    p_resp_parm + len    );
                   break;
           case EEPROM_READ_ERROR:
                   len += PutAsciiParam( (BIT8 *)"CANT READ EEPROM, ",        p_resp_parm + len    );
                   break;
            default:
                    len += PutAsciiParam( (BIT8 *)"UNKNOWN ERROR!,",          p_resp_parm + len    );
                    break;
        }

        len += PutIntParam( (INT32)(offset*1000),     p_resp_parm + len, 3 );
        len += PutAsciiParam( (BIT8 *)",",            p_resp_parm + len    );
        len += PutIntParam( (INT32)(span  *1000),     p_resp_parm + len, 3 );
        len += PutAsciiParam( (BIT8 *)",",            p_resp_parm + len    );
        len += PutIntParam( (INT32)(doffset_dt*1000), p_resp_parm + len, 3 );
        len += PutAsciiParam( (BIT8 *)",",            p_resp_parm + len    );
        len += PutIntParam( (INT32)(dspan_dt*1000),   p_resp_parm + len, 3 );
   }
   else
   {
               len += PutAsciiParam( (BIT8 *)"?? ",     p_resp_parm );
               len += PutIntParam(  (INT32) error,      p_resp_parm+len, 0 );
   }

   return len;
}


INT16 DoTPYT(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )

{
   UI_ERR  error;
   U_INT16 module  = 0;
   int     len     = 0;
   float   offset  = 0.0;
   float   span    = 0.0;

/**begin_doc**/
    /*                                                                                                   */
    /*  Writes converted thermistor constants to EEPROM                                                  */
    /*                                                                                                   */
    /*   TPYT module_num, offset, span                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
    /*   module_num   0 - frnt inlet        where is the manifold we are messing with?                   */
    /*                1 - back inlet                                                                     */
    /*                2 - frnr det                                                                       */
    /*                3 - back det                                                                       */
    /*                4 - pneu aux                                                                       */
    /*                                                                                                   */
    /*   offset       thermistor voltage at 25C  (V)                        real, 3 decimal digits       */
    /*   span         temp sensitivity (mV/C)                               real, 3 decimal digits       */
    /*                                                                                                   */
    /*                                                                                                   */
/**end_doc**/
   
   error = OK;

   if ( p_cmd->parmv[0] != 3 )  error = MISSING_PARAM;

   if ( error == OK )  error = GetAWordParam( p_cmd,  1, &module      );

   if ( error == OK )  error = GetReal( p_cmd,  2, &offset     );
   if ( error == OK )  error = GetReal( p_cmd,  3, &span       );

   if ( module   > 4 ) error = INVALID_PARAM;

   span  /= 1000;  /* convert to volts */

   len = 0;

   if ( error == OK ) 
   {
        switch( SaveThermisterConstants ( module, offset, 25.0, span * 25.0 ))
        {
           case OK: len += PutAsciiParam( (BIT8 *)"OK,",          p_resp_parm + len    );
                   break;
           case OVFLOW_V25C:
                   len += PutAsciiParam( (BIT8 *)"OVERFLOW V25,",p_resp_parm + len    );
                   break;
           case OVFLOW_DT:
                   len += PutAsciiParam( (BIT8 *)"OVERFLOW dT,", p_resp_parm + len    );
                   break;
           case OVFLOW_DV:
                   len += PutAsciiParam( (BIT8 *)"OVERFLOW dV,", p_resp_parm + len    );
                   break;
           case ZERO_DV:
                   len += PutAsciiParam( (BIT8 *)"ZERO dV,",     p_resp_parm + len    );
                   break;
           case EEPROM_WRITE_ERROR:
                   len += PutAsciiParam( (BIT8 *)"CANT WRITE TO EEPROM, ", p_resp_parm + len    );
                   break;
           case EEPROM_READ_ERROR:
                   len += PutAsciiParam( (BIT8 *)"CANT READ EEPROM, ",     p_resp_parm + len    );
                   break;
            default:
                    len += PutAsciiParam( (BIT8 *)"UNKNOWN ERROR!,",          p_resp_parm + len    );
                    break;
        }

        len += PutIntParam( (INT32)(offset *1000),     p_resp_parm + len, 3 );
        len += PutAsciiParam( (BIT8 *)",",            p_resp_parm + len    );
        len += PutIntParam( (INT32)(span    *1000),  p_resp_parm + len, 3 );
        return len;
   }
   else
   {
               len += PutAsciiParam( (BIT8 *)"?? ",     p_resp_parm );
               len += PutIntParam( (INT32) error,       p_resp_parm+len, 0 );
   }

   return len;
}


INT16 DoTPZP(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   UI_ERR  error;

   U_INT16 range       = 0;
   U_INT16 module      = 0;
   U_INT16 position    = 0;

   float   pres  [4];
   float   temp  [4];
   U_INT16 counts[4];

   float   offset      = 0.0;
   float   span        = 0.0;
   float   doffset_dt  = 0.0;
   float   dspan_dt    = 0.0;

   int     len         = 0;

   error = OK;

/**begin_doc**/
    /*                                                                                                   */
    /*  do a four point calibration on a pressure sensor and save results in eeprom                      */
    /*                                                                                                   */
    /*   TPZP module_num, sensor_range, sensor_position, p1, p2, p3, p4, t1, t2, t3, t4, v1, v2, v3, v4  */
    /*                                                                                                   */
    /*   module_num   0 - frnt inlet        where is the manifold we are messing with?                   */
    /*                1 - back inlet                                                                     */
    /*                2 - frnr det                                                                       */
    /*                3 - back det                                                                       */
    /*                4 - pneu aux                                                                       */
    /*                                                                                                   */
    /*   sensor_range  15, 100, or 150      max pres for this sensor in PSIG  (integer)                  */
    /*                                                                                                   */
    /*   sensor_position   1  - inlet p sensor, detector fuel, or aux3                                   */
    /*                     2  -                 detector util, or aux4                                   */
    /*                     3  -                 detector mug,  or aux5                                   */
    /*                                                                                                   */
    /*                                                                                                   */
    /*   p1, p2, p3, p4    pressure (real, 3 decimal digits) in PSIG                                     */
    /*                                                                                                   */
    /*   t1, t2, t3, t4    temperature (real, 3 decimal digits) in degrees C                             */
    /*                                                                                                   */
    /*   v1, v2, v3, v4    sensor voltage in counts reported by the IQ DTPV command,                     */
    /*                       (filtered, adc offset corrected)                                            */
    /*                                                                                                   */
    /*                                                                                                   */
    /* Returns:                                                                                          */
    /*                                                                                                   */
    /*   TPZP OK,offset, span, doffset_dt, dspan_dt           if all ok                                  */
    /*   TPZP ??                                              on failure                                 */
    /*                                                                                                   */
    /*      offset, span             volts                                                               */
    /*      doffset_dt, dspan_dt     volts / C                                                           */
    /*                                                                                                   */
    /*                                                                                                   */
    /*  bad number errors                                                                                */
    /*                                                                                                   */
    /*   TPZP OVERFLOW OFFSET                                                                            */
    /*   TPZP OVERFLOW SPAN                                                                              */
    /*   TPZP OVERFLOW dOFFSET/dT                                                                        */
    /*   TPZP OVERFLOW dSPAN/dT                                                                          */
    /*   TPZP ZERO RANGE                                                                                 */
    /*   TPZP ZERO SCALE                                                                                 */
    /*   TPZP ZERO OFFSET                                                                                */
    /*   TPZP ZERO SPAN                                                                                  */
    /*   TPZP UNKNOWN ERROR!                                                                             */
    /*                                                                                                   */
    /*                                                                                                   */
/**end_doc**/

   if ( p_cmd->parmv[0] != 15 )  error = MISSING_PARAM;

   if ( error == OK )  error = GetAWordParam( p_cmd,  1, &module      );
   if ( error == OK )  error = GetAWordParam( p_cmd,  2, &range       );
   if ( error == OK )  error = GetAWordParam( p_cmd,  3, &position    );

   if ( error == OK )  error = GetReal( p_cmd,  4, &pres[ 0 ] );
   if ( error == OK )  error = GetReal( p_cmd,  5, &pres[ 1 ] );
   if ( error == OK )  error = GetReal( p_cmd,  6, &pres[ 2 ] );
   if ( error == OK )  error = GetReal( p_cmd,  7, &pres[ 3 ] );

   if ( error == OK )  error = GetReal( p_cmd,  8, &temp[ 0 ] );
   if ( error == OK )  error = GetReal( p_cmd,  9, &temp[ 1 ] );
   if ( error == OK )  error = GetReal( p_cmd, 10, &temp[ 2 ] );
   if ( error == OK )  error = GetReal( p_cmd, 11, &temp[ 3 ] );

   if ( error == OK )  error = GetAWordParam( p_cmd, 12, &counts[ 0 ] );
   if ( error == OK )  error = GetAWordParam( p_cmd, 13, &counts[ 1 ] );
   if ( error == OK )  error = GetAWordParam( p_cmd, 14, &counts[ 2 ] );
   if ( error == OK )  error = GetAWordParam( p_cmd, 15, &counts[ 3 ] );

   len = 0;

   if ( error == OK )
   {
        switch( DoAPresSensor( module, position, range, pres, temp, counts,
                                              &offset, &span, &doffset_dt, &dspan_dt  ) )
        {
            case OK: len += PutAsciiParam( (BIT8 *)"OK,",          p_resp_parm + len    );
                    break;
            case  OVFLOW_PS_OFFSET:
                    len += PutAsciiParam( (BIT8 *)"OVERFLOW OFFSET,",         p_resp_parm + len    );
                    break;
            case  OVFLOW_PS_SPAN:
                    len += PutAsciiParam( (BIT8 *)"OVERFLOW SPAN,",           p_resp_parm + len    );
                    break;
            case  OVFLOW_PS_DOFFSET:
                    len += PutAsciiParam( (BIT8 *)"OVERFLOW dOFFSET/dT,",     p_resp_parm + len    );
                    break;
            case  OVFLOW_PS_DSPAN:
                    len += PutAsciiParam( (BIT8 *)"OVERFLOW dSPAN/dT,",       p_resp_parm + len    );
                    break;
            case  ZERO_PS_RANGE:
                    len += PutAsciiParam( (BIT8 *)"ZERO RANGE,",              p_resp_parm + len    );
                    break;
            case  ZERO_PS_DCM2:
                    len += PutAsciiParam( (BIT8 *)"ZERO SCALE,",              p_resp_parm + len    );
                    break;
            case  ZERO_PS_OFFSET:
                    len += PutAsciiParam( (BIT8 *)"ZERO OFFSET,",             p_resp_parm + len    );
                    break;
            case  ZERO_PS_SPAN:
                    len += PutAsciiParam( (BIT8 *)"ZERO SPAN,",               p_resp_parm + len    );
                    break;
           case EEPROM_WRITE_ERROR:
                   len += PutAsciiParam( (BIT8 *)"CANT WRITE TO EEPROM, ", p_resp_parm + len    );
                   break;
           case EEPROM_READ_ERROR:
                   len += PutAsciiParam( (BIT8 *)"CANT READ EEPROM, ",     p_resp_parm + len    );
                   break;
            default:
                    len += PutAsciiParam( (BIT8 *)"UNKNOWN ERROR!,",          p_resp_parm + len    );
                    break;
        }

        len += PutIntParam( (INT32)(offset*1000),     p_resp_parm + len, 3 );
        len += PutAsciiParam( (BIT8 *)",",            p_resp_parm + len    );
        len += PutIntParam( (INT32)(span  *1000),     p_resp_parm + len, 3 );
        len += PutAsciiParam( (BIT8 *)",",            p_resp_parm + len    );
        len += PutIntParam( (INT32)(doffset_dt*1000000.0), p_resp_parm + len, 6 );
        len += PutAsciiParam( (BIT8 *)",",            p_resp_parm + len    );
        len += PutIntParam( (INT32)(dspan_dt*1000000.0),   p_resp_parm + len, 6 );

   }
   else            len += PutAsciiParam( (BIT8 *)"??",     p_resp_parm );

   return len;
}



INT16 DoTPZF(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   UI_ERR  error;

   U_INT16 module     = 0;
   U_INT16 gas_type   = 0;

   float   ref_flow   = 0.0;   
   float   max_flow   = 0.0;
   float   temp  [2];
   U_INT16 counts[8];

   float alpha_low    = 0.0;
   float alpha_high   = 0.0;
   float beta_low     = 0.0;
   float beta_high    = 0.0;
   float offset       = 0.0;
   float switch_flow  = 0.0;
   float da_dt        = 0.0;
   float db_dt        = 0.0;
   float dvo_dt       = 0.0;
   float ref_temp     = 0.0;

   int     len;

   error = OK;

/**begin_doc**/
    /*                                                                                                   */
    /*  do a four point calibration on a flow sensor and save results in eeprom                          */
    /*                                                                                                   */
    /*   TPZF module_num, gas_type, max_flow, ref_flow, t0, t1, vo1, vf1, v3f1, v9f1, vo2, vf2, v3f2, v9f2*/
    /*                                                                                                   */
    /*   module_num   0 - frnt inlet        where is the manifold we are messing with?                   */
    /*                1 - back inlet                                                                     */
    /*                2 - frnr det                                                                       */
    /*                3 - back det                                                                       */
    /*                4 - pneu aux                                                                       */
    /*                                                                                                   */
    /*   gas_type     0  N2                                                                              */
    /*                1  H2                                                                              */
    /*                2  He                                                                              */
    /*                3  ArMe                                                                            */
    /*                6  Ar                                                                              */
    /*                                                                                                   */
    /*   max_flow     maximum flow allowed for inlet SCCM                                                */
    /*                                                                                                   */
    /*   ref_flow     SCCM, (real, 3 decimal digits )                                                    */
    /*                                                                                                   */
    /*   t0, t1       the two temps in degrees C for the measurements  ( real, 3 decimal digits )        */
    /*                                                                                                   */
    /*   vo1,v02      offset at teh two temps (counts from DTPV)                                         */
    /*   vf1,vf2      sensor voltage at 1* ref_flow  (counts from DTPV)                                  */
    /*   v3f1,v3f2    sensor voltage at 3* ref_flow  (counts)                                            */
    /*   v9f1,v9f2    sensor voltage at 9* ref_flow  (counts)                                            */
    /*                                                                                                   */
    /*                                                                                                   */
    /* Returns:                                                                                          */
    /*                                                                                                   */
    /*  TPZF ??       if number of parms, or bad numbers comming in                                      */
    /*                                                                                                   */
    /*                                                                                                   */
    /*  TPZF OK, alpha_low, beta_low, alpha_high, beta_high, offset, dalpha_dt, dbeta_dt, doffset_dt     */
    /*                                                                                                   */
    /*    alpha_low, alpha_high, offset   volts                                                          */
    /*    beta_low,  beta_high            unitless                                                       */
    /*    dalpha_dt, doffset_dt           volts/C                                                        */
    /*    dbeta_dt                        1/C                                                            */
    /*                                                                                                   */
    /*  Bad Number returns    cant use calculated numbers                                                */
    /*                                                                                                   */
    /*    TPZF OVERFLOW AH                                                                               */
    /*    TPZF OVERFLOW AL                                                                               */
    /*    TPZF OVERFLOW BH                                                                               */
    /*    TPZF OVERFLOW BL                                                                               */
    /*    TPZF OVERFLOW Vo                                                                               */
    /*    TPZF OVERFLOW Tr                                                                               */
    /*    TPZF OVERFLOW Fm                                                                               */
    /*    TPZF OVERFLOW dA                                                                               */
    /*    TPZF OVERFLOW dB                                                                               */
    /*    TPZF OVERFLOW dVo                                                                              */
    /*    TPZF ZERO Vo                                                                                   */
    /*    TPZF ZERO AL                                                                                   */
    /*    TPZF ZERO BL                                                                                   */
    /*    TPZF BAD Fswitch                                                                               */
    /*                                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
    /*  Funnies:                                                                                         */
    /*                                                                                                   */
    /*     if vf2, v3f2           is zero, dalpha_dt, dbeta_dt will be 0.                                */
    /*     if v9f1                is zero, alpha_high, beta_high wil be undefined and unused.            */
    /*                                                                                                   */
/**end_doc**/
    

   if ( p_cmd->parmv[0] != 14 )  error = MISSING_PARAM;

   if ( error == OK )  error = GetAWordParam( p_cmd,  1, &module      );
   if ( error == OK )  error = GetAWordParam( p_cmd,  2, &gas_type     );

   if ( error == OK )  error = GetReal( p_cmd,  3, &max_flow );
   if ( error == OK )  error = GetReal( p_cmd,  4, &ref_flow );

   if ( error == OK )  error = GetReal( p_cmd,  5, &temp[ 0 ] );
   if ( error == OK )  error = GetReal( p_cmd,  6, &temp[ 1 ] );


   if ( error == OK )  error = GetAWordParam( p_cmd,  7, &counts[ 0 ] );  /* low t  offset */
   if ( error == OK )  error = GetAWordParam( p_cmd,  8, &counts[ 1 ] );  /* low t  V 1f   */
   if ( error == OK )  error = GetAWordParam( p_cmd,  9, &counts[ 2 ] );  /* low t  V 3f   */
   if ( error == OK )  error = GetAWordParam( p_cmd, 10, &counts[ 3 ] );  /* low t  V 9f   */
   if ( error == OK )  error = GetAWordParam( p_cmd, 11, &counts[ 4 ] );  /* high t offset */
   if ( error == OK )  error = GetAWordParam( p_cmd, 12, &counts[ 5 ] );  /* high t V 1f   */
   if ( error == OK )  error = GetAWordParam( p_cmd, 13, &counts[ 6 ] );  /* high t V 3f   */
   if ( error == OK )  error = GetAWordParam( p_cmd, 14, &counts[ 7 ] );  /* high t V 9f   */

   len = 0;

   if ( error == OK )
   {
        error = DoAFlowSensor( module, (GAS_TYPE)gas_type, ref_flow, max_flow, temp, counts, &alpha_low, &alpha_high,
                               &beta_low, &beta_high, &offset, &switch_flow, &da_dt, &db_dt, &dvo_dt, &ref_temp );

        if (( error == OVFLOW_FS_ALPHA_LOW ) ||
            ( error == OVFLOW_FS_BETA_LOW  ))  
        {
             /* alpha low or beta low didn't work.  try forcing alpha to a max value and calc a beta */

             error = DoAFlowSensorTry2( module, (GAS_TYPE)gas_type, ref_flow, max_flow, temp, counts, &alpha_low, &alpha_high,
                                    &beta_low, &beta_high, &offset, &switch_flow, &da_dt, &db_dt, &dvo_dt, &ref_temp );


             if (( error == OVFLOW_FS_ALPHA_LOW ) ||
                 ( error == OVFLOW_FS_BETA_LOW  ) ||
                 ( error == ZERO_FS_ALPHA_LOW   ) ||
                 ( error == ZERO_FS_BETA_LOW    ) )
             {
                  /* alpha low or beta low didn't work.  try using 3f, 9f and see if we get a good answer */
    
                  error = DoAFlowSensorTry3( module, (GAS_TYPE)gas_type, ref_flow, max_flow, temp, counts, &alpha_low, &alpha_high,
                                         &beta_low, &beta_high, &offset, &switch_flow, &da_dt, &db_dt, &dvo_dt, &ref_temp );
             }
        }
      

        switch( error )
        {
           case OK:
                   len += PutAsciiParam( (BIT8 *)"OK,",          p_resp_parm + len    );
                   break;
           case OVFLOW_FS_ALPHA_HIGH:
                   len += PutAsciiParam( (BIT8 *)"OVERFLOW AH,", p_resp_parm + len    );
                   break;
           case OVFLOW_FS_ALPHA_LOW:
                   len += PutAsciiParam( (BIT8 *)"OVERFLOW AL,", p_resp_parm + len    );
                   break;
           case OVFLOW_FS_BETA_HIGH:
                   len += PutAsciiParam( (BIT8 *)"OVERFLOW BH,", p_resp_parm + len    );
                   break;
           case OVFLOW_FS_BETA_LOW:
                   len += PutAsciiParam( (BIT8 *)"OVERFLOW BL,", p_resp_parm + len    );
                   break;
           case OVFLOW_FS_OFFSET:
                   len += PutAsciiParam( (BIT8 *)"OVERFLOW Vo,", p_resp_parm + len    );
                   break;
           case OVFLOW_FS_REF_TEMP:
                   len += PutAsciiParam( (BIT8 *)"OVERFLOW Tr,", p_resp_parm + len    );
                   break;
           case OVFLOW_FS_MAX_FLOW:
                   len += PutAsciiParam( (BIT8 *)"OVERFLOW Fm,", p_resp_parm + len    );
                   break;
           case OVFLOW_FS_DALPHA:
                   len += PutAsciiParam( (BIT8 *)"OVERFLOW dA,", p_resp_parm + len    );
                   break;
           case OVFLOW_FS_DBETA:
                   len += PutAsciiParam( (BIT8 *)"OVERFLOW dB,", p_resp_parm + len    );
                   break;
           case OVFLOW_FS_DOFFSET:
                   len += PutAsciiParam( (BIT8 *)"OVERFLOW dVo,",p_resp_parm + len    );
                   break;
           case ZERO_FS_OFFSET:
                   len += PutAsciiParam( (BIT8 *)"ZERO Vo,",     p_resp_parm + len    );
                   break;
           case ZERO_FS_ALPHA_LOW:
                   len += PutAsciiParam( (BIT8 *)"ZERO AL,",     p_resp_parm + len    );
                   break;
           case ZERO_FS_BETA_LOW:
                   len += PutAsciiParam( (BIT8 *)"ZERO BL,",     p_resp_parm + len    );
                   break;
           case BAD_SWITCH_FLOW:
                   len += PutAsciiParam( (BIT8 *)"BAD Fswitch,", p_resp_parm + len    );
                   break;
           case EEPROM_WRITE_ERROR:
                   len += PutAsciiParam( (BIT8 *)"CANT WRITE TO EEPROM, ", p_resp_parm + len    );
                   break;
           case EEPROM_READ_ERROR:
                   len += PutAsciiParam( (BIT8 *)"CANT READ EEPROM, ",     p_resp_parm + len    );
                   break;
            default:
                    len += PutAsciiParam( (BIT8 *)"UNKNOWN ERROR #",          p_resp_parm + len    );
                    len += PutIntParam( (INT32)(error),           p_resp_parm + len,    0 );
                    len += PutAsciiParam( (BIT8 *)",",          p_resp_parm + len    );
                    break;
        }

        len += PutIntParam( (INT32)(alpha_low*1000),  p_resp_parm + len,    3 );
        len += PutAsciiParam( (BIT8 *)",",            p_resp_parm + len    );
        len += PutIntParam( (INT32)(beta_low *1000000),  p_resp_parm + len, 6 );
        len += PutAsciiParam( (BIT8 *)",",            p_resp_parm + len    );
        len += PutIntParam( (INT32)(alpha_high*1000), p_resp_parm + len,    3 );
        len += PutAsciiParam( (BIT8 *)",",            p_resp_parm + len    );
        len += PutIntParam( (INT32)(beta_high *1000000), p_resp_parm + len, 6 );
        len += PutAsciiParam( (BIT8 *)",",            p_resp_parm + len    );
        len += PutIntParam( (INT32)(offset    *1000), p_resp_parm + len,    3 );
        len += PutAsciiParam( (BIT8 *)",",            p_resp_parm + len    );
        len += PutIntParam( (INT32)(da_dt     *1000000), p_resp_parm + len, 6 );
        len += PutAsciiParam( (BIT8 *)",",            p_resp_parm + len    );
        len += PutIntParam( (INT32)(db_dt     *1000000), p_resp_parm + len, 6 );
        len += PutAsciiParam( (BIT8 *)",",            p_resp_parm + len    );
        len += PutIntParam( (INT32)(dvo_dt    *1000000), p_resp_parm + len, 6 );
        return len;
   }
   else               return  PutAsciiParam( (BIT8 *)"??",     p_resp_parm );

}



INT16 DoTPQS(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   UI_ERR  error;

   U_INT16 module      = 0;

   float   flow  [8];
   float   pres  [8];

   float   ref_flow[4];
   float   df_dp[4];
  
   U_INT16 checksum    = 0;

   int     len         = 0;

   error = OK;

/**begin_doc**/
    /*                                                                                                   */
    /*  do a two point linear calibration for the septum purge regulator and return programmable values  */
    /*                                                                                                   */
    /*                              -----N2---- ----H2----- ----He----- ---ArMe----                      */
    /*   TPQS module_num, gas_type, f1,f2,p1,p2,f1,f2,p1,p2,f1,f2,p1,p2,f1,f2,p1,p2                      */
    /*                                                                                                   */
    /*   module_num   0 - frnt inlet        where is the manifold we are messing with?                   */
    /*                1 - back inlet                                                                     */
    /*                2 - frnr det                                                                       */
    /*                3 - back det                                                                       */
    /*                4 - pneu aux                                                                       */
    /*                                                                                                   */
    /*   gas_type     0  N2                                                                              */
    /*                1  H2                                                                              */
    /*                2  He                                                                              */
    /*                3  ArMe                                                                            */
    /*                6  Ar                                                                              */
    /*                                                                                                   */
    /*   f1, f2       measured septum purge flow SCCM, (real, 3 decimal digits )                         */
    /*                                                                                                   */
    /*   p1, p2       the two pressures PSIG (real, 3 decimal digits) for the flow measurements          */ 
    /*                                                                                                   */
    /*                                                                                                   */
    /*  Returns                                                                                          */
    /*                                                                                                   */
    /*    TPQS ??     invalid parms or number of parms                                                   */
    /*                                                                                                   */
    /*              -------N2-----  ------H2------  -------He-----  -----ArMe-----                       */
    /*    TPQS  OK, ref_flow,df_dp, ref_flow,df_dp, ref_flow,df_dp, ref_flow,df_dp, checksum             */
    /*                                                                                                   */
    /*  Bad Number Returns                                                                               */
    /*                                                                                                   */
    /*    TPQS OVERFLOW Fp                                                                               */
    /*    TPQS OVERFLOW dF/dP                                                                            */
    /*    TPQS ZERO Fp                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
/**end_doc**/
    
   if ( p_cmd->parmv[0] != 17 )  error = MISSING_PARAM;

   if ( error == OK )  error = GetAWordParam( p_cmd,  1, &module      );

   if ( error == OK )  error = GetReal( p_cmd,  2, &flow[ 0 ] );
   if ( error == OK )  error = GetReal( p_cmd,  3, &flow[ 1 ] );
   if ( error == OK )  error = GetReal( p_cmd,  4, &pres[ 0 ] );
   if ( error == OK )  error = GetReal( p_cmd,  5, &pres[ 1 ] );

   if ( error == OK )  error = GetReal( p_cmd,  6, &flow[ 2 ] );
   if ( error == OK )  error = GetReal( p_cmd,  7, &flow[ 3 ] );
   if ( error == OK )  error = GetReal( p_cmd,  8, &pres[ 2 ] );
   if ( error == OK )  error = GetReal( p_cmd,  9, &pres[ 3 ] );

   if ( error == OK )  error = GetReal( p_cmd, 10, &flow[ 4 ] );
   if ( error == OK )  error = GetReal( p_cmd, 11, &flow[ 5 ] );
   if ( error == OK )  error = GetReal( p_cmd, 12, &pres[ 4 ] );
   if ( error == OK )  error = GetReal( p_cmd, 13, &pres[ 5 ] );

   if ( error == OK )  error = GetReal( p_cmd, 14, &flow[ 6 ] );
   if ( error == OK )  error = GetReal( p_cmd, 15, &flow[ 7 ] );
   if ( error == OK )  error = GetReal( p_cmd, 16, &pres[ 6 ] );
   if ( error == OK )  error = GetReal( p_cmd, 17, &pres[ 7 ] );

        len = 0;
                    
   if ( error == OK )
   {
        switch( GetPurgeRegProgConsts ( module, flow, pres, ref_flow, df_dp, &checksum ) )
        {
            case OK: 
                 len += PutAsciiParam( (BIT8 *)"OK,",          p_resp_parm + len    );
                 break;
            case OVFLOW_PURGE_FLOW:
                 len += PutAsciiParam( (BIT8 *)"OVERFLOW Fp,", p_resp_parm + len    );
                 break;
            case OVFLOW_DF_DP:
                 len += PutAsciiParam( (BIT8 *)"OVERFLOW dF/dP,", p_resp_parm + len    );
                 break;
            case ZERO_PURGE_FLOW:
                 len += PutAsciiParam( (BIT8 *)"ZERO Fp,",     p_resp_parm + len    );
                 break;
            default:
                    len += PutAsciiParam( (BIT8 *)"UNKNOWN ERROR!,",          p_resp_parm + len    );
                    break;
        }

        len += PutIntParam( (INT32)(ref_flow[0]      ),  p_resp_parm + len, 3 );
        len += PutAsciiParam( (BIT8 *)",",               p_resp_parm + len    );
        len += PutIntParam( (INT32)(df_dp[0]         ),  p_resp_parm + len, 3 );
        len += PutAsciiParam( (BIT8 *)",",               p_resp_parm + len    );

        len += PutIntParam( (INT32)(ref_flow[1]      ),  p_resp_parm + len, 3 );
        len += PutAsciiParam( (BIT8 *)",",               p_resp_parm + len    );
        len += PutIntParam( (INT32)(df_dp[1]         ),  p_resp_parm + len, 3 );
        len += PutAsciiParam( (BIT8 *)",",               p_resp_parm + len    );

        len += PutIntParam( (INT32)(ref_flow[2]      ),  p_resp_parm + len, 3 );
        len += PutAsciiParam( (BIT8 *)",",               p_resp_parm + len    );
        len += PutIntParam( (INT32)(df_dp[2]         ),  p_resp_parm + len, 3 );
        len += PutAsciiParam( (BIT8 *)",",               p_resp_parm + len    );

        len += PutIntParam( (INT32)(ref_flow[3]      ),  p_resp_parm + len, 3 );
        len += PutAsciiParam( (BIT8 *)",",               p_resp_parm + len    );
        len += PutIntParam( (INT32)(df_dp[3]         ),  p_resp_parm + len, 3 );
        len += PutAsciiParam( (BIT8 *)",",               p_resp_parm + len    );

        len += PutIntParam( (INT32)(checksum),           p_resp_parm + len, 0 );

        return len;
   }
   else               return  PutAsciiParam( (BIT8 *)"??",     p_resp_parm );

}



INT16 DoTPZS(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   UI_ERR  error;

   U_INT16 module     = 0;
   U_INT16 gas_type   = 0;

   float   flow  [2];
   float   pres  [2];

   float   ref_flow   = 0.0;
   float   df_dp      = 0.0;

   int     len        = 0;

   error = OK;

/**begin_doc**/
    /*                                                                                                   */
    /*  do a two point linear calibration for the septum purge regulator and store results in EEPROM     */
    /*                                                                                                   */
    /*  W A R N I N G !!  TPZP, the pressure sensor initialization _MUST_ be done before TPZS!           */
    /*                                                                                                   */
    /*                                                                                                   */
    /*   TPZS module_num, gas_type, f1, f2, p1, p2                                                       */
    /*                                                                                                   */
    /*   module_num   0 - frnt inlet        where is the manifold we are messing with?                   */
    /*                1 - back inlet                                                                     */
    /*                2 - frnr det                                                                       */
    /*                3 - back det                                                                       */
    /*                4 - pneu aux                                                                       */
    /*                                                                                                   */
    /*   gas_type     0  N2                                                                              */
    /*                1  H2                                                                              */
    /*                2  He                                                                              */
    /*                3  ArMe                                                                            */
    /*                6  Ar                                                                              */
    /*                                                                                                   */
    /*   f1, f2       measured septum purge flow SCCM, (real, 3 decimal digits )                         */
    /*                                                                                                   */
    /*   p1, p2       the two pressures PSIG (real, 3 decimal digits) for the flow measurements          */ 
    /*                                                                                                   */
    /*                                                                                                   */
    /*  Returns                                                                                          */
    /*                                                                                                   */
    /*    TPZS ??     invalid parms or number of parms                                                   */
    /*                                                                                                   */
    /*    TPZS  OK, ref_flow, df_dp       if all is ok                                                   */
    /*                                                                                                   */
    /*  Bad Number Returns                                                                               */
    /*                                                                                                   */
    /*    TPZS OVERFLOW Fp                                                                               */
    /*    TPZS OVERFLOW dF/dP                                                                            */
    /*    TPZS ZERO Fp                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
/**end_doc**/
    
   if ( p_cmd->parmv[0] != 6 )  error = MISSING_PARAM;

   if ( error == OK )  error = GetAWordParam( p_cmd,  1, &module      );
   if ( error == OK )  error = GetAWordParam( p_cmd,  2, &gas_type     );

   if ( error == OK )  error = GetReal( p_cmd,  3, &flow[ 0 ] );
   if ( error == OK )  error = GetReal( p_cmd,  4, &flow[ 1 ] );

   if ( error == OK )  error = GetReal( p_cmd,  5, &pres[ 0 ] );
   if ( error == OK )  error = GetReal( p_cmd,  6, &pres[ 1 ] );

        len = 0;
                    
   if ( error == OK )
   {
        switch( DoAPurgeReg ( module, (GAS_TYPE)gas_type, flow, pres, &ref_flow, &df_dp ) )
        {
            case OK: 
                 len += PutAsciiParam( (BIT8 *)"OK,",          p_resp_parm + len    );
                 break;
            case OVFLOW_PURGE_FLOW:
                 len += PutAsciiParam( (BIT8 *)"OVERFLOW Fp,", p_resp_parm + len    );
                 break;
            case OVFLOW_DF_DP:
                 len += PutAsciiParam( (BIT8 *)"OVERFLOW dF/dP,", p_resp_parm + len    );
                 break;
            case ZERO_PURGE_FLOW:
                 len += PutAsciiParam( (BIT8 *)"ZERO Fp,",     p_resp_parm + len    );
                 break;
            default:
                    len += PutAsciiParam( (BIT8 *)"UNKNOWN ERROR!,",          p_resp_parm + len    );
                    break;
        }
        len += PutIntParam( (INT32)(ref_flow *1000),  p_resp_parm + len, 3 );
        len += PutAsciiParam( (BIT8 *)",",            p_resp_parm + len    );
        len += PutIntParam( (INT32)(df_dp    *1000),  p_resp_parm + len, 3 );
        return len;
   }
   else               return  PutAsciiParam( (BIT8 *)"??",     p_resp_parm );

}



INT16 DoTPZT(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   UI_ERR  error;

   U_INT16 module     = 0;

   float   temp  [2];
   U_INT16 counts[2];

   float   v_25c      = 0;
   float   dv_dt      = 0;

   int     len        = 0;

   error = OK;

/**begin_doc**/
    /*                                                                                                   */
    /*  do a two point linear calibration for the temperature sensor and store results in EEPROM         */
    /*                                                                                                   */
    /*   TPZT module_num, t1, t2, v1, v2                                                                 */
    /*                                                                                                   */
    /*   module_num   0 - frnt inlet        where is the manifold we are messing with?                   */
    /*                1 - back inlet                                                                     */
    /*                2 - frnr det                                                                       */
    /*                3 - back det                                                                       */
    /*                4 - pneu aux                                                                       */
    /*                                                                                                   */
    /*   t1, t2       the two temperature measurements in degrees C (real, 3 decimal digits)             */
    /*                                                                                                   */
    /*   v1, v2       senor voltage in counts as returned by DTMT                                        */ 
    /*                                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
    /* Returns                                                                                           */
    /*                                                                                                   */
    /*   TPZT ??   invalid parms or number of parms                                                      */
    /*                                                                                                   */
    /*   TPZT  v25c, dt, sv     if all is ok                                                             */
    /*                                                                                                   */
    /*   v25c  counts, voltage for the temp sensor at 25 degrees c                                       */
    /*                                                                                                   */
    /*   dt    a delta temp in degrees C                                                                 */
    /*                                                                                                   */
    /*   dv    a change in counts corresponding to a dt change in temperature                            */
    /*                                                                                                   */
    /*                                                                                                   */
    /*  Bad number returns                                                                               */
    /*                                                                                                   */
    /*   TPZT OVERFLOW V25                                                                               */
    /*   TPZT OVERFLOW dT                                                                                */
    /*   TPZT OVERFLOW dV                                                                                */
    /*   TPZT ZERO dV                                                                                    */
    /*   TPZT UNKNOWN ERROR!                                                                             */
    /*                                                                                                   */
    /*                                                                                                   */
/**end_doc**/
    
   if ( p_cmd->parmv[0] != 5 )  error = MISSING_PARAM;

   if ( error == OK )  error = GetAWordParam( p_cmd,  1, &module      );

   if ( error == OK )  error = GetReal( p_cmd,  2, &temp[ 0 ] );
   if ( error == OK )  error = GetReal( p_cmd,  3, &temp[ 1 ] );

   if ( error == OK )  error = GetAWordParam( p_cmd,  4, &counts[ 0 ] );
   if ( error == OK )  error = GetAWordParam( p_cmd,  5, &counts[ 1 ] );

                    
   len = 0;
   if ( error == OK )
   {
        switch( DoATempSensor ( module, temp, counts, &v_25c, &dv_dt ) )
        {
           case OK: len += PutAsciiParam( (BIT8 *)"OK,",          p_resp_parm + len    );
                   break;
           case OVFLOW_V25C:
                   len += PutAsciiParam( (BIT8 *)"OVERFLOW V25,",p_resp_parm + len    );
                   break;
           case OVFLOW_DT:
                   len += PutAsciiParam( (BIT8 *)"OVERFLOW dT,", p_resp_parm + len    );
                   break;
           case OVFLOW_DV:
                   len += PutAsciiParam( (BIT8 *)"OVERFLOW dV,", p_resp_parm + len    );
                   break;
           case ZERO_DV:
                   len += PutAsciiParam( (BIT8 *)"ZERO dV,",     p_resp_parm + len    );
                   break;
           case EEPROM_WRITE_ERROR:
                   len += PutAsciiParam( (BIT8 *)"CANT WRITE TO EEPROM, ", p_resp_parm + len    );
                   break;
            default:
                    len += PutAsciiParam( (BIT8 *)"UNKNOWN ERROR!,",          p_resp_parm + len    );
                    break;
        }

        len += PutIntParam( (INT32)(v_25c *1000),     p_resp_parm + len, 3 );
        len += PutAsciiParam( (BIT8 *)",",            p_resp_parm + len    );
        len += PutIntParam( (INT32)(dv_dt    *1000),  p_resp_parm + len, 3 );
        return len;
   }
   else               return  PutAsciiParam( (BIT8 *)"??",     p_resp_parm );

}



INT16 DoTPCJ(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   UI_ERR  error;
   U_INT16 module        = 0;
   int     len;
   U_INT16 i;
   U_INT16 mode          = 0;
   U_INT32 value         = 0;
   U_INT16 pres_volts, flow_volts;
   float   pres_value, flow_value;
   error = OK;

/**begin_doc**/
    /*                                                                                                   */
    /*  Control a jack in the box                                                                        */
    /*                                                                                                   */
    /*   TPCJ module_num, pres_value, flow_value, pres_volts, flow_volts                                 */
    /*                                                                                                   */
    /*                                                                                                   */
    /*       ** Specify only one of pres_value, flow_value, pres_volts, flow_volts **                    */
    /*                                                                                                   */
    /*                                                                                                   */
    /*   module_num   0 - frnt inlet        where is the manifold we are messing with?                   */
    /*                1 - back inlet                                                                     */
    /*                2 - frnr det                                                                       */
    /*                3 - back det                                                                       */
    /*                4 - pneu aux                                                                       */
    /*                                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
    /*   pres_value    PSI real 3 decimal digits   ( 30.125 )                                            */
    /*                                                                                                   */
    /*   flow_value    sccm, real, 3 decimal digits  ( 48.480 )                                          */
    /*                                                                                                   */
    /*   pres_volts, flow_volts   counts, as returned from TPRP, TPRF                                    */
    /*                                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
/**end_doc**/
   
   error = OK;

   if ( p_cmd->parmv[0] < 1 )  error = MISSING_PARAM;

   if ( error == OK )  error = GetAWordParam( p_cmd,  1, &module      );

   mode = 0;  /* off */

   if (error == OK )
   for ( i = 2; i < 6 ; i++ )
   {
       if ( ParamPresent ( p_cmd, i ) )
       {
           switch ( i )
           {
              case 2: error = GetReal      ( p_cmd,  2, &pres_value );
                      mode  = 1;
                      value = (U_INT32)(pres_value * 68947.57);  /* psi to d/cm2 */
                      break;
              case 3: error = GetReal      ( p_cmd,  3, &flow_value );
                      mode  = 2;
                      value = (U_INT32)(flow_value * 1000 * 298.15 / 273.15 );
                      break;
              case 4: error = GetAWordParam( p_cmd,  4, &pres_volts );
                      mode  = 3;
                      value = pres_volts;
                      break;
              case 5: error = GetAWordParam( p_cmd,  5, &flow_volts );
                      mode  = 4;
                      value = flow_volts;
                      break;
           }
           break;
       }
   }

   if ( error == OK )   error = ControlJackInTheBox( module, mode, value );

   len = 0;

   if ( error == OK ) len += PutAsciiParam( (BIT8 *)"OK",     p_resp_parm );
   else               len += PutAsciiParam( (BIT8 *)"??",     p_resp_parm );

   return len;
}



INT16 DoTPJS(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   UI_ERR  error;
   U_INT16 module = 0;
   int     len    = 0;
   INT16 state    = 0;

   error = OK;
   len = 0;


/**begin_doc**/
    /*                                                                                                   */
    /*  request/set jill status                                                                          */
    /*                                                                                                   */
    /*   TPJS module_num, on/off            Set                                                          */
    /*   TPJS module_num                    Request                                                      */
    /*                                                                                                   */
    /*                                                                                                   */
    /*   setting a jill's state off causes her to loose her setpoints.  they must be restored            */
    /*   by a CJ command (which sets the state to on)                                                    */
    /*                                                                                                   */
    /*                                                                                                   */
    /*   module_num   0 - frnt inlet        where is the manifold we are messing with?                   */
    /*                1 - back inlet                                                                     */
    /*                2 - frnr det                                                                       */
    /*                3 - back det                                                                       */
    /*                4 - pneu aux                                                                       */
    /*                                                                                                   */
    /*                                                                                                   */
    /*   status  0 off                                                                                   */
    /*           1 on                                                                                    */
    /*          -1 shutdown                                                                              */
    /*                                                                                                   */
    /*                                                                                                   */
    /*                                                                                                   */
/**end_doc**/
   
   error = OK;

   if ( p_cmd->parmv[0] < 1 )  error = MISSING_PARAM;

   if ( error == OK )  error = GetAWordParam( p_cmd,  1, &module      );

   if (error == OK )
   {
       if ( ParamPresent ( p_cmd, 2 ) )
       {
           error = GetAWordParam( p_cmd,  2, (U_INT16 *)&state );
    
           if ( error == OK ) error = SetJackState( module, state );
    
           if ( error == OK ) len += PutAsciiParam( (BIT8 *)"OK",     p_resp_parm );
           else               len += PutAsciiParam( (BIT8 *)"??",     p_resp_parm );
       }
       else
       {
           state = GetJackState( module );
     
           switch ( state )
           {
              case 0:  len += PutAsciiParam( (BIT8 *)"OFF",     p_resp_parm ); break;
              case 1:  len += PutAsciiParam( (BIT8 *)"ON",      p_resp_parm ); break;
              case-1:  len += PutAsciiParam( (BIT8 *)"SHUTDOWN",p_resp_parm ); break;
              default: len += PutAsciiParam( (BIT8 *)"error!"  ,p_resp_parm ); break;
           }
       }
   }
        
   return len;
}


INT16 DoTPSP(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{

    U_INT16 p1   = 0;
    U_INT16 p2   = 0;
    U_INT16 p3   = 0;
    U_INT16 p4   = 0;
    U_INT16 vp1  = 0;
    U_INT16 vp2  = 0;
    U_INT16 vp3  = 0;
    U_INT16 vp4  = 0;
    U_INT16 module = 0;
    UI_ERR  error;

/**begin_doc**/
    /*                                                                                                   */
    /*  Save pressure calibration values from jack in the box                                            */
    /*                                                                                                   */
    /*   TPSP module_num, p1, p2, p3, p4, vp1, vp2, vp3, vp4                                             */
    /*                                                                                                   */
    /*   p1,p2,p3,p4   Pressures, PSIG * 100   ( 5 psi = 500 )                                           */
    /*                                                                                                   */
    /*   vp1,vp2,vp3,vp4  Sensor voltage at the specified pressure point from DTPV                       */
    /*                                                                                                   */
    /*                                                                                                   */
    /*  Returns:                                                                                         */
    /*                                                                                                   */
    /*   TPSP OK                                                                                         */
    /*   TPSP ??                                                                                         */
    /*                                                                                                   */
/**end_doc**/

   error = OK;
   if ( p_cmd->parmv[0] != 9 )  error = MISSING_PARAM;
   if ( error == OK )  error = GetAWordParam( p_cmd,  1, &module      );
   if ( error == OK )  error = GetAWordParam( p_cmd,  2, &p1          );
   if ( error == OK )  error = GetAWordParam( p_cmd,  3, &p2          );
   if ( error == OK )  error = GetAWordParam( p_cmd,  4, &p3          );
   if ( error == OK )  error = GetAWordParam( p_cmd,  5, &p4          );
   if ( error == OK )  error = GetAWordParam( p_cmd,  6, &vp1         );
   if ( error == OK )  error = GetAWordParam( p_cmd,  7, &vp2         );
   if ( error == OK )  error = GetAWordParam( p_cmd,  8, &vp3         );
   if ( error == OK )  error = GetAWordParam( p_cmd,  9, &vp4         );

   if ( error == OK )
   {
      error = SavePCalibConstants( module, p1, p2, p3, p4, vp1, vp2, vp3, vp4 );
   }

   if ( error == OK ) return  PutAsciiParam( (BIT8 *)"OK",     p_resp_parm  );
   else               return  PutAsciiParam( (BIT8 *)"??",     p_resp_parm );
}



INT16 DoTPSF(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{

    U_INT16 flow  = 0;
    U_INT16 v1    = 0;
    U_INT16 v2    = 0;
    U_INT16 v3    = 0;
    U_INT16 v4    = 0;
    U_INT16 v5    = 0;
    U_INT16 v6    = 0;
    U_INT16 v7    = 0;
    U_INT16 v8    = 0;
    U_INT16 module= 0;
    U_INT16 gas   = 0;
    UI_ERR  error;

/**begin_doc**/
    /*                                                                                                   */
    /*  Save flow calibration values from jack in the box                                                */
    /*                                                                                                   */
    /*   TPSF module_num, gas,  flow, v1, v2, v3, v4, v5, v6, v7, v8                                     */
    /*                                                                                                   */
    /*                                                                                                   */
    /*   gas          0  N2                                                                              */
    /*                1  H2                                                                              */
    /*                2  He                                                                              */
    /*                3  ArMe                                                                            */
    /*                                                                                                   */
    /*   flow          reference flow, sccm * 100  ( 48.48 sccm = 4848 )                                 */
    /*                                                                                                   */
    /*   v1, v2, v3, v4, v5, v6, v7, v8 voltages in counts (from DTPV) related  to the ref flow          */
    /*                                                                                                   */
    /*                                                                                                   */
    /*  Returns:                                                                                         */
    /*                                                                                                   */
    /*   TPSF OK                                                                                         */
    /*   TPSF ??                                                                                         */
/**end_doc**/

   error = OK;
   if ( p_cmd->parmv[0] != 11 )  error = MISSING_PARAM;
   if ( error == OK )  error = GetAWordParam( p_cmd,  1, &module      );
   if ( error == OK )  error = GetAWordParam( p_cmd,  2, &gas         );
   if ( error == OK )  error = GetAWordParam( p_cmd,  3, &flow        );
   if ( error == OK )  error = GetAWordParam( p_cmd,  4, &v1         );
   if ( error == OK )  error = GetAWordParam( p_cmd,  5, &v2         );
   if ( error == OK )  error = GetAWordParam( p_cmd,  6, &v3         );
   if ( error == OK )  error = GetAWordParam( p_cmd,  7, &v4         );
   if ( error == OK )  error = GetAWordParam( p_cmd,  8, &v5         );
   if ( error == OK )  error = GetAWordParam( p_cmd,  9, &v6         );
   if ( error == OK )  error = GetAWordParam( p_cmd, 10, &v7         );
   if ( error == OK )  error = GetAWordParam( p_cmd, 11, &v8         );


   if ( error == OK )
   {
      error = SaveFCalibConstants( module, (GAS_TYPE)gas, flow, v1, v2, v3, v4, v5, v6, v7, v8 );
   }

   if ( error == OK ) return  PutAsciiParam( (BIT8 *)"OK",     p_resp_parm  );
   else               return  PutAsciiParam( (BIT8 *)"??",     p_resp_parm );
}




INT16 DoTPRP(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{

    U_INT16 p1     = 0;
    U_INT16 p2     = 0;
    U_INT16 p3     = 0;
    U_INT16 p4     = 0;
    U_INT16 vp1    = 0;
    U_INT16 vp2    = 0;
    U_INT16 vp3    = 0;
    U_INT16 vp4    = 0;
    U_INT16 module = 0;
    INT16   len;
    UI_ERR  error;

/**begin_doc**/
    /*                                                                                                   */
    /*  Read pressure calibration values from jack in the box                                            */
    /*                                                                                                   */
    /*   TPRP module_num                                                                                 */
    /*                                                                                                   */
    /*                                                                                                   */
    /*  Returns:                                                                                         */
    /*                                                                                                   */
    /*   TPRP OK, p1, p2, p3, p4, vp1, vp2, vp3, vp4                                                     */
    /*                                                                                                   */
    /*   p1,p2,p3,p4   Pressures, PSIG * 100   ( 5 psi = 500 )                                           */
    /*                                                                                                   */
    /*   vp1,vp2,vp3,vp4  Sensor voltage at the specified pressure point from DTPV                       */
    /*                                                                                                   */
    /*                                                                                                   */
/**end_doc**/

   error = OK;
   if ( p_cmd->parmv[0] != 1 )  error = MISSING_PARAM;
   if ( error == OK )  error = GetAWordParam( p_cmd,  1, &module      );

   if ( error == OK )
   {
      error = ReadPCalibConstants( module, &p1,  &p2,  &p3,  &p4, &vp1, &vp2, &vp3, &vp4 );
   }

   if ( error == OK )
   {
        len = 0;
        len += PutAsciiParam( (BIT8 *)"OK,",     p_resp_parm  );
        len += PutIntParam( (INT32)p1,           p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",       p_resp_parm + len    );
        len += PutIntParam( (INT32)p2,           p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",       p_resp_parm + len    );
        len += PutIntParam( (INT32)p3,           p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",       p_resp_parm + len    );
        len += PutIntParam( (INT32)p4,           p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",       p_resp_parm + len    );
        len += PutIntParam( (INT32)vp1,          p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",       p_resp_parm + len    );
        len += PutIntParam( (INT32)vp2,          p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",       p_resp_parm + len    );
        len += PutIntParam( (INT32)vp3,          p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",       p_resp_parm + len    );
        len += PutIntParam( (INT32)vp4,          p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",       p_resp_parm + len    );
        return len;
   }
   else               return  PutAsciiParam( (BIT8 *)"??",     p_resp_parm );
}



INT16 DoTPRF(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{

    U_INT16 flow    = 0;
    U_INT16 v1      = 0;
    U_INT16 v2      = 0;
    U_INT16 v3      = 0;
    U_INT16 v4      = 0;
    U_INT16 v5      = 0;
    U_INT16 v6      = 0;
    U_INT16 v7      = 0;
    U_INT16 v8      = 0;
    U_INT16 module  = 0;
    U_INT16 gas     = 0;
    INT16   len;
    UI_ERR  error;

/**begin_doc**/
    /*                                                                                                   */
    /*  Read flow calibration values from jack in the box                                                */
    /*                                                                                                   */
    /*   TPRF module_num, gas_type                                                                       */
    /*                                                                                                   */
    /*   gas_type     0  N2                                                                              */
    /*                1  H2                                                                              */
    /*                2  He                                                                              */
    /*                3  ArMe                                                                            */
    /*                                                                                                   */
    /*                                                                                                   */
    /*  Returns:                                                                                         */
    /*                                                                                                   */
    /*   TPRF OK, flow, v1, v2, v3, v4, v5, v6, v7, v8                                                   */
    /*                                                                                                   */
    /*   flow          reference flow, sccm * 100  ( 48.48 sccm = 4848 )                                 */
    /*                                                                                                   */
    /*   v1f,v2f,v3f,v6f,v9f flow sensor voltages from DTPV for multiples of reference flow              */
    /*                                                                                                   */
    /*                                                                                                   */
/**end_doc**/

   error = OK;
   if ( p_cmd->parmv[0] != 2 )  error = MISSING_PARAM;
   if ( error == OK )  error = GetAWordParam( p_cmd,  1, &module      );
   if ( error == OK )  error = GetAWordParam( p_cmd,  2, &gas         );


   if ( error == OK )
   {
      error = ReadFCalibConstants( module, (GAS_TYPE)gas, &flow, &v1, &v2, &v3, &v4, &v5, &v6, &v7, &v8 );
   }

   if ( error == OK )
   {
        len = 0;
        len += PutAsciiParam( (BIT8 *)"OK,",    p_resp_parm  );
        len += PutIntParam( (INT32)flow,        p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",      p_resp_parm + len    );
        len += PutIntParam( (INT32)v1,          p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",      p_resp_parm + len    );
        len += PutIntParam( (INT32)v2,          p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",      p_resp_parm + len    );
        len += PutIntParam( (INT32)v3,          p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",      p_resp_parm + len    );
        len += PutIntParam( (INT32)v4,          p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",      p_resp_parm + len    );
        len += PutIntParam( (INT32)v5,          p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",      p_resp_parm + len    );
        len += PutIntParam( (INT32)v6,          p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",      p_resp_parm + len    );
        len += PutIntParam( (INT32)v7,          p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",      p_resp_parm + len    );
        len += PutIntParam( (INT32)v8,          p_resp_parm + len, 0 );
        len += PutAsciiParam( (BIT8 *)",",      p_resp_parm + len    );
        return len;
   }
   else               return  PutAsciiParam( (BIT8 *)"??",     p_resp_parm );
}

#if 0




INT16 DoTPCF(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   UI_ERR   error;
   U_INT16  module  = 0;
   U_INT16  gas_num = 0;
   U_INT16  alpha1  = 0;
   U_INT16  alpha2  = 0;
   U_INT16  beta1   = 0;
   U_INT16  beta2   = 0;

   error = OK;

   if (  p_cmd->parmv[0] == 6 )
   {
        if ( error == OK ) error = GetAWordParam( p_cmd, 1, &module );
        if ( error == OK ) error = GetAWordParam( p_cmd, 2, &gas_num );
        if ( error == OK ) error = GetAWordParam( p_cmd, 3, &alpha1 );
        if ( error == OK ) error = GetAWordParam( p_cmd, 4, &alpha2 );
        if ( error == OK ) error = GetAWordParam( p_cmd, 5, &beta1  );
        if ( error == OK ) error = GetAWordParam( p_cmd, 6, &beta2  );

        if (( module != 2 ) && ( module != 3 ))
        {
             error = INVALID_PARAM;
        }

        if (( gas_num != 1 ) && ( gas_num != 2 ) && ( gas_num != 3 ))
        {
             error = INVALID_PARAM;
        }

        if ( error == OK )
        {
            if ( module == 2 ) KLUDGE_LoadFritParms( &Inst_Status.Pneu.Frnt_Detector, gas_num, 
                               (((U_INT32)alpha1 << 16) | alpha2 ), (((U_INT32)beta1 << 16) | beta2) );
            else               KLUDGE_LoadFritParms( &Inst_Status.Pneu.Back_Detector, gas_num,
                               (((U_INT32)alpha1 << 16) | alpha2 ), (((U_INT32)beta1 << 16) | beta2) );
   
        }
   }
   else
   {
       error = MISSING_PARAM;
   }

   if ( error == OK ) return PutAsciiParam( (BIT8 *)"OK",     p_resp_parm );
   else               return PutAsciiParam( (BIT8 *)"??",     p_resp_parm );

}



INT16 DoTPCT(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   UI_ERR   error;
   U_INT16  module = 0;
   U_INT16  v_25c  = 0;
   INT16    dv     = 0;
   INT16    dt     = 0;

   error = OK;

   if (  p_cmd->parmv[0] == 4 )
   {
        if ( error == OK ) error = GetAWordParam( p_cmd, 1, &module );
        if ( error == OK ) error = GetAWordParam( p_cmd, 2, &v_25c );
        if ( error == OK ) error = GetAWordParam( p_cmd, 3, (U_INT16 *)&dv  );
        if ( error == OK ) error = GetAWordParam( p_cmd, 4, (U_INT16 *)&dt  );

        if (( module != 2 ) && ( module != 3 ))
        {
             error = INVALID_PARAM;
        }

        if ( error == OK )
        {
            if ( module == 2 ) KLUDGE_LoadThermParms( &Inst_Status.Pneu.Frnt_Detector, v_25c, dv, dt );
            else               KLUDGE_LoadThermParms( &Inst_Status.Pneu.Back_Detector, v_25c, dv, dt );
            
        }
   }
   else
   {
       error = MISSING_PARAM;
   }

   if ( error == OK ) return PutAsciiParam( (BIT8 *)"OK",     p_resp_parm );
   else               return PutAsciiParam( (BIT8 *)"??",     p_resp_parm );

}


INT16 DoTPCP(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   UI_ERR   error;
   U_INT16  module   = 0;
   U_INT16  gas_num  = 0;
   U_INT16  offset   = 0;
   U_INT16  span     = 0;
   INT16    d_o      = 0;
   INT16    d_s      = 0;

   error = OK;

   if (  p_cmd->parmv[0] == 6 )
   {
        if ( error == OK ) error = GetAWordParam( p_cmd, 1, &module );
        if ( error == OK ) error = GetAWordParam( p_cmd, 2, &gas_num );
        if ( error == OK ) error = GetAWordParam( p_cmd, 3, &offset );
        if ( error == OK ) error = GetAWordParam( p_cmd, 4, &span );
        if ( error == OK ) error = GetAWordParam( p_cmd, 5, (U_INT16 *)&d_o  );
        if ( error == OK ) error = GetAWordParam( p_cmd, 6, (U_INT16 *)&d_s  );

        if (( module != 2 ) && ( module != 3 ))
        {
             error = INVALID_PARAM;
        }

        if (( gas_num != 1 ) && ( gas_num != 2 ) && ( gas_num != 3 ))
        {
             error = INVALID_PARAM;
        }

        if ( error == OK )
        {
            if ( module == 2 ) KLUDGE_LoadPsParms( &Inst_Status.Pneu.Frnt_Detector, gas_num, offset, span, d_o, d_s );
            else               KLUDGE_LoadPsParms( &Inst_Status.Pneu.Back_Detector, gas_num, offset, span, d_o, d_s );
        }
   }
   else
   {
       error = MISSING_PARAM;
   }

   if ( error == OK ) return PutAsciiParam( (BIT8 *)"OK",     p_resp_parm );
   else               return PutAsciiParam( (BIT8 *)"??",     p_resp_parm );

}


INT16 DoTPPV(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{


   UI_ERR   error;
   U_INT16  length   = 0;
   U_INT16  module   = 0;
   U_INT16  gas_num  = 0;
   U_INT16  pres     = 0;
   U_INT16  temp     = 0;
   U_INT16  volts    = 0;

   error = OK;

   if (  p_cmd->parmv[0] == 4 )
   {
        if ( error == OK ) error = GetAWordParam( p_cmd, 1, &module );
        if ( error == OK ) error = GetAWordParam( p_cmd, 2, &gas_num );
        if ( error == OK ) error = GetAWordParam( p_cmd, 3, &pres );
        if ( error == OK ) error = GetAWordParam( p_cmd, 4, &temp );

  

        if ( error == OK )
        {
             if ( module == 2 )
             {
                 switch ( gas_num )
                 {
                     case 1:  volts = PresToVolts( pres,
                                                   &Inst_Status.Pneu.Frnt_Detector.Gas_1.Tcomp_Tables->Pres_Sensor,
                                                   temp );
                              break;
                     case 2:  volts = PresToVolts( pres,
                                                   &Inst_Status.Pneu.Frnt_Detector.Gas_2.Tcomp_Tables->Pres_Sensor,
                                                   temp );
                              break;
                     case 3:  volts = PresToVolts( pres,
                                                   &Inst_Status.Pneu.Frnt_Detector.Gas_3.Tcomp_Tables->Pres_Sensor,
                                                   temp );
                              break;
                     default:   error = INVALID_PARAM;
 
                 }
             }
             else if ( module == 3 )
             {
                 switch ( gas_num )
                 {
                     case 1:  volts = PresToVolts( pres,
                                                   &Inst_Status.Pneu.Back_Detector.Gas_1.Tcomp_Tables->Pres_Sensor,
                                                   temp );
                              break;
                     case 2:  volts = PresToVolts( pres,
                                                   &Inst_Status.Pneu.Back_Detector.Gas_2.Tcomp_Tables->Pres_Sensor,
                                                   temp );
                              break;
                     case 3:  volts = PresToVolts( pres,
                                                   &Inst_Status.Pneu.Back_Detector.Gas_3.Tcomp_Tables->Pres_Sensor,
                                                   temp );
                              break;
                     default:   error = INVALID_PARAM;
                 }
             }
        }
        else error = INVALID_PARAM;

   }
   else
   {
       error = MISSING_PARAM;
   }

   if ( error != OK ) return PutAsciiParam( (BIT8 *)"??",     p_resp_parm );
   
   length = PutHexParam( SubtractAdcOffset(volts), p_resp_parm);

   return length;

}



INT16 DoTPVP(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{

   UI_ERR   error;
   U_INT16  length   = 0;
   U_INT16  module   = 0;
   U_INT16  gas_num  = 0;
   U_INT16  pres     = 0;
   U_INT16  temp     = 0;
   U_INT16  volts    = 0;

   error = OK;

   if (  p_cmd->parmv[0] == 4 )
   {
        if ( error == OK ) error = GetAWordParam( p_cmd, 1, &module );
        if ( error == OK ) error = GetAWordParam( p_cmd, 2, &gas_num );
        if ( error == OK ) error = GetAWordParam( p_cmd, 3, &volts);
        if ( error == OK ) error = GetAWordParam( p_cmd, 4, &temp );

  
        volts = AddAdcOffset( volts );

        if ( error == OK )
        {
             if ( module == 2 )
             {
                 switch ( gas_num )
                 {
                     case 1:  pres  = VoltsToPres ( volts,
                                                   &Inst_Status.Pneu.Frnt_Detector.Gas_1.Tcomp_Tables->Pres_Sensor,
                                                   temp );
                              break;
                     case 2:  pres  = VoltsToPres ( volts,
                                                   &Inst_Status.Pneu.Frnt_Detector.Gas_2.Tcomp_Tables->Pres_Sensor,
                                                   temp );
                              break;
                     case 3:  pres  = VoltsToPres ( volts,
                                                   &Inst_Status.Pneu.Frnt_Detector.Gas_3.Tcomp_Tables->Pres_Sensor,
                                                   temp );
                              break;
                     default:   error = INVALID_PARAM;
 
                 }
             }
             else if ( module == 3 )
             {
                 switch ( gas_num )
                 {
                     case 1:  pres  = VoltsToPres ( volts,
                                                   &Inst_Status.Pneu.Back_Detector.Gas_1.Tcomp_Tables->Pres_Sensor,
                                                   temp );
                              break;
                     case 2:  pres  = VoltsToPres ( volts,
                                                   &Inst_Status.Pneu.Back_Detector.Gas_2.Tcomp_Tables->Pres_Sensor,
                                                   temp );
                              break;
                     case 3:  pres  = VoltsToPres ( volts,
                                                   &Inst_Status.Pneu.Back_Detector.Gas_3.Tcomp_Tables->Pres_Sensor,
                                                   temp );
                              break;
                     default:   error = INVALID_PARAM;
                 }
             }
        }
        else error = INVALID_PARAM;

   }
   else
   {
       error = MISSING_PARAM;
   }

   if ( error != OK ) return PutAsciiParam( (BIT8 *)"??",     p_resp_parm );

   length = PutHexParam( pres, p_resp_parm);

   return length;

}



INT16 DoTPVT(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{

   UI_ERR   error;
   U_INT16  length  = 0;
   U_INT16  module  = 0;
   U_INT16  temp    = 0;
   U_INT16  volts   = 0;

   error = OK;

   if (  p_cmd->parmv[0] == 2 )
   {
        if ( error == OK ) error = GetAWordParam( p_cmd, 1, &module );
        if ( error == OK ) error = GetAWordParam( p_cmd, 2, &volts);

        if ( error == OK )
        {
             if ( module == 2 )
             {
                temp = tableU ( (U_INT16 *)Inst_Status.Pneu.Frnt_Detector.Tcomp_Tables->Thermistor.Volts_To_Temp, volts );
             }
             else if ( module == 3 )
             {
                temp = tableU ( (U_INT16 *)Inst_Status.Pneu.Back_Detector.Tcomp_Tables->Thermistor.Volts_To_Temp, volts );
             }
        }
        else error = INVALID_PARAM;

   }
   else
   {
       error = MISSING_PARAM;
   }

   if ( error != OK ) return PutAsciiParam( (BIT8 *)"??",     p_resp_parm );

   length = PutHexParam( temp, p_resp_parm);

   return length;

}





U_INT16 FritFlowToPres ( U_INT32 desired_flow, pFRIT_STRUCT frit,          U_INT16 module_temperature, U_INT16 atm_pres );
U_INT32 FritPresToFlow ( U_INT16 pres,         pFRIT_STRUCT frit,          U_INT16 module_temperature, U_INT16 atm_pres );

INT16 DoTPPF(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{

   UI_ERR   error;
   U_INT16  length  = 0;
   U_INT16  module  = 0;
   U_INT16  gas_num = 0;
   U_INT16  pres    = 0;
   U_INT16  po      = 0;
   U_INT16  temp    = 0;
   U_INT32  flow    = 0;

   error = OK;

   if (  p_cmd->parmv[0] == 5 )
   {
        if ( error == OK ) error = GetAWordParam( p_cmd, 1, &module );
        if ( error == OK ) error = GetAWordParam( p_cmd, 2, &gas_num );
        if ( error == OK ) error = GetAWordParam( p_cmd, 3, &pres);
        if ( error == OK ) error = GetAWordParam( p_cmd, 4, &po );
        if ( error == OK ) error = GetAWordParam( p_cmd, 5, &temp );

  

        if ( error == OK )
        {
             if ( module == 2 )
             {
                 switch ( gas_num )
                 {
                     case 1:  flow  = FritPresToFlow  ( pres,
                                                   &Inst_Status.Pneu.Frnt_Detector.Gas_1.Tcomp_Tables->Frit,
                                                   temp, po );
                              flow = QuadWordMultiplyDivide(flow, 1000, Inst_Status.Pneu.Frnt_Detector.IU_Scaling);
                              break;
                     case 2:  flow  = FritPresToFlow  ( pres,
                                                   &Inst_Status.Pneu.Frnt_Detector.Gas_2.Tcomp_Tables->Frit,
                                                   temp, po );
                              flow = QuadWordMultiplyDivide(flow, 1000, Inst_Status.Pneu.Frnt_Detector.IU_Scaling);
                              break;
                     case 3:  flow  = FritPresToFlow  ( pres,
                                                   &Inst_Status.Pneu.Frnt_Detector.Gas_3.Tcomp_Tables->Frit,
                                                   temp, po );
                              flow = QuadWordMultiplyDivide(flow, 1000, Inst_Status.Pneu.Frnt_Detector.IU_Scaling);
                              break;
                     default:   error = INVALID_PARAM;
 
                 }
             }
             else if ( module == 3 )
             {
                 switch ( gas_num )
                 {
                     case 1:  flow  = FritPresToFlow  ( pres,
                                                   &Inst_Status.Pneu.Back_Detector.Gas_1.Tcomp_Tables->Frit,
                                                   temp, po );
                              flow = QuadWordMultiplyDivide(flow, 1000, Inst_Status.Pneu.Back_Detector.IU_Scaling);
                              break;
                     case 2:  flow  = FritPresToFlow  ( pres,
                                                   &Inst_Status.Pneu.Back_Detector.Gas_2.Tcomp_Tables->Frit,
                                                   temp, po );
                              flow = QuadWordMultiplyDivide(flow, 1000, Inst_Status.Pneu.Back_Detector.IU_Scaling);
                              break;
                     case 3:  flow  = FritPresToFlow  ( pres,
                                                   &Inst_Status.Pneu.Back_Detector.Gas_3.Tcomp_Tables->Frit,
                                                   temp, po );
                              flow = QuadWordMultiplyDivide(flow, 1000, Inst_Status.Pneu.Back_Detector.IU_Scaling);
                              break;
                     default:   error = INVALID_PARAM;
                 }
             }
        }
        else error = INVALID_PARAM;

   }
   else
   {
       error = MISSING_PARAM;
   }

   if ( error != OK ) return PutAsciiParam( (BIT8 *)"??",     p_resp_parm );

   length = PutIntParam( flow, p_resp_parm, 3 );

   return length;

}


INT16 DoTPFP(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{

   UI_ERR   error;
   U_INT16  length  = 0;
   U_INT16  module  = 0;
   U_INT16  gas_num = 0;
   U_INT16  pres    = 0;
   U_INT16  po      = 0;
   U_INT16  temp    = 0;
   U_INT32  flow    = 0;

   error = OK;

   if (  p_cmd->parmv[0] == 5 )
   {
        if ( error == OK ) error = GetAWordParam( p_cmd, 1, &module );
        if ( error == OK ) error = GetAWordParam( p_cmd, 2, &gas_num );
        if ( error == OK ) error = DecToInt( &p_cmd->parms[p_cmd->parmv[3]], 3, (INT32 *)&flow );
        if ( error == OK ) error = GetAWordParam( p_cmd, 4, &po );
        if ( error == OK ) error = GetAWordParam( p_cmd, 5, &temp );
    
        
  
        if ( error == OK )
        {
             if ( module == 2 )
             {
                 switch ( gas_num )
                 {
                     case 1:  pres  = FritFlowToPres  ( QuadWordMultiplyDivide(flow,
                                                                Inst_Status.Pneu.Frnt_Detector.IU_Scaling,
                                                                1000),
                                                   &Inst_Status.Pneu.Frnt_Detector.Gas_1.Tcomp_Tables->Frit,
                                                   temp, po );
                              break;
                     case 2:  pres  = FritFlowToPres  ( QuadWordMultiplyDivide(flow,
                                                                Inst_Status.Pneu.Frnt_Detector.IU_Scaling,
                                                                1000),
                                                   &Inst_Status.Pneu.Frnt_Detector.Gas_2.Tcomp_Tables->Frit,
                                                   temp, po );
                              break;
                     case 3:  pres  = FritFlowToPres  ( QuadWordMultiplyDivide(flow,
                                                                Inst_Status.Pneu.Frnt_Detector.IU_Scaling,
                                                                1000),
                                                   &Inst_Status.Pneu.Frnt_Detector.Gas_3.Tcomp_Tables->Frit,
                                                   temp, po );
                              break;
                     default:   error = INVALID_PARAM;
 
                 }
             }
             else if ( module == 3 )
             {
                 switch ( gas_num )
                 {
                     case 1:  pres  = FritFlowToPres  ( QuadWordMultiplyDivide(flow,
                                                                Inst_Status.Pneu.Back_Detector.IU_Scaling,
                                                                1000),
                                                   &Inst_Status.Pneu.Back_Detector.Gas_1.Tcomp_Tables->Frit,
                                                   temp, po );
                              break;
                     case 2:  pres  = FritFlowToPres  ( QuadWordMultiplyDivide(flow,
                                                                Inst_Status.Pneu.Back_Detector.IU_Scaling,
                                                                1000),
                                                   &Inst_Status.Pneu.Back_Detector.Gas_2.Tcomp_Tables->Frit,
                                                   temp, po );
                              break;
                     case 3:  pres  = FritFlowToPres  ( QuadWordMultiplyDivide(flow,
                                                                Inst_Status.Pneu.Back_Detector.IU_Scaling,
                                                                1000),
                                                   &Inst_Status.Pneu.Back_Detector.Gas_3.Tcomp_Tables->Frit,
                                                   temp, po );
                              break;
                     default:   error = INVALID_PARAM;
                 }
             }
        }
        else error = INVALID_PARAM;

   }
   else
   {
       error = MISSING_PARAM;
   }

   if ( error != OK ) return PutAsciiParam( (BIT8 *)"??",     p_resp_parm );

   length = PutHexParam( pres, p_resp_parm );

   return length;

}

#endif

INT16 DoTPIF(CMD_TYPE *p_cmd, BIT8 *p_resp_parm, pINLET_STATUS status )
{
   INT32 len;

   len = 0;

   len += PutIntParam( ConvertPresIuToDcu( status->Inlet_Pressure_Setpt,
                                               status->Dcm2_Per_IU), 
                                      p_resp_parm + len, 0 );
   len += PutAsciiParam( (BIT8 *)",", p_resp_parm + len    );


   len += PutIntParam( ConvertPresIuToDcu( status->Delayed_NTP_Inlet_Pres_Setpt,
                                               status->Dcm2_Per_IU), 
                                      p_resp_parm + len, 0 );
   len += PutAsciiParam( (BIT8 *)",", p_resp_parm + len    );


   len += PutIntParam( ConvertPresIuToDcu( status->Compensated_Pressure,
                                               status->Dcm2_Per_IU), 
                                      p_resp_parm + len, 0 );
   len += PutAsciiParam( (BIT8 *)",", p_resp_parm + len    );


   len += PutIntParam( ConvertPresIuToDcu( status->Filtered_Inlet_Pressure_Setpt,
                                               status->Dcm2_Per_IU), 
                                      p_resp_parm + len, 0 );
   len += PutAsciiParam( (BIT8 *)",", p_resp_parm + len    );


   len += PutIntParam( ConvertPresIuToDcu( status->Delayed_Inlet_Pressure_Setpt,
                                               status->Dcm2_Per_IU), 
                                      p_resp_parm + len, 0 );
   len += PutAsciiParam( (BIT8 *)",", p_resp_parm + len    );


   len += PutIntParam( ConvertPresIuToDcu( status->Filtered_Current_Pressure,
                                               status->Dcm2_Per_IU), 
                                      p_resp_parm + len, 0 );
   len += PutAsciiParam( (BIT8 *)",", p_resp_parm + len    );


   len += PutIntParam( ConvertPresIuToDcu( status->NTP_Adjusted_Current_Pressure,
                                               status->Dcm2_Per_IU), 
                                      p_resp_parm + len, 0 );
   len += PutAsciiParam( (BIT8 *)",", p_resp_parm + len    );


   len += PutIntParam( ConvertPresIuToDcu( status->Ready.Pres.Actual, status->Dcm2_Per_IU) -
                       ConvertPresIuToDcu( status->Ready.Pres.Setpt, status->Dcm2_Per_IU), 
                                      p_resp_parm + len, 0 );
   len += PutAsciiParam( (BIT8 *)",", p_resp_parm + len    );



   return len;

}

#endif                                        /* end   code for "1st" include */

#define RW_PROCS
